Imports System.ComponentModel

Imports DevExpress.XtraBars

Imports Phoenix.Events

Namespace Forms.Area

    Public Class AreaBase
        Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            '
            'AreaBase
            '
            Me.Name = "AreaBase"
            Me.Size = New System.Drawing.Size(360, 448)

        End Sub

#End Region

#Region " Area Behaviour "
        Private mContextMenu As PopupMenu
        Public Shadows Property ContextMenu() As PopupMenu
            Get
                Return mContextMenu
            End Get
            Set(ByVal Value As PopupMenu)
                mContextMenu = Value
            End Set
        End Property

        Public Sub ShowContextMenu()
            If ContextMenu Is Nothing Then Return

            ContextMenu.ShowPopup(Control.MousePosition)
        End Sub


        Public Delegate Function DefaultActionDelegate(ByVal item As Object) As ChildFormBase
        Public DefaultAction As DefaultActionDelegate

        Public Overridable Sub DoDefaultAction()
            Throw New InvalidOperationException
        End Sub

        Public Overridable Function CanCopy() As Boolean

            Return False
        End Function

        Public Overridable Function CanCut() As Boolean
            Return False
        End Function

        Public Overridable Function CanDelete() As Boolean
            Return False
        End Function

        Public Overridable ReadOnly Property SelectedItems() As IList
            Get
                Throw New InvalidOperationException
            End Get
        End Property

#Region " Allow Operations "
        Public Function AllowCopy(ByVal array As IList) As Boolean
            If array Is Nothing Then
                Return False
            End If
            If array.Count = 0 Then
                Return False
            End If
            For Each obj As Object In array
                If Not AllowCopyItem(obj) Then
                    Return False
                End If
            Next
            Return True
        End Function

        Public Function AllowCut(ByVal array As IList) As Boolean
            If array Is Nothing Then
                Return False
            End If
            If array.Count = 0 Then
                Return False
            End If
            For Each obj As Object In array
                If Not AllowCutItem(obj) Then
                    Return False
                End If
            Next
            Return True
        End Function

        Public Function AllowDelete(ByVal array As IList) As Boolean
            If array Is Nothing Then
                Return False
            End If
            If array.Count = 0 Then
                Return False
            End If
            For Each obj As Object In array
                If Not AllowDeleteItem(obj) Then
                    Return False
                End If
            Next
            Return True
        End Function

#End Region

        Protected Overridable Function AllowCopyItem(ByVal obj As Object) As Boolean
            Return CanCopy()
        End Function

        Protected Overridable Function AllowCutItem(ByVal obj As Object) As Boolean
            Return CanCut()
        End Function

        Protected Overridable Function AllowDeleteItem(ByVal obj As Object) As Boolean
            Return CanDelete()
        End Function

        Public Overridable Sub SelectAll()
            Throw New InvalidOperationException
        End Sub

        Public Overridable Function Copy(ByVal arr As IList) As IList
            Throw New InvalidOperationException
        End Function

        Public Overridable Sub Cut(ByVal arr As IList)
            Throw New InvalidOperationException
        End Sub

        Public Overridable Sub Delete(ByVal arr As IList)
            Throw New InvalidOperationException
        End Sub

        Public Overridable Sub Paste(ByVal arr As IList)
            Throw New InvalidOperationException
        End Sub
#End Region

#Region " Event Handlers "
        Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            AddHandler PhoenixApplication.AppNotification, AddressOf Application_Notification
        End Sub

        Private Sub Application_Notification(ByVal sender As Object, ByVal e As PhoenixEventArgs)
            OnApplicationEvent(sender, e)
        End Sub

        Protected Overridable Sub OnApplicationEvent(ByVal sender As Object, ByVal e As PhoenixEventArgs)

        End Sub

#End Region

    End Class
End Namespace
